﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInputControl.h"

namespace gnuf {
    class Info;

    class GNUF_BASE_EXPORT ICheckGroupControlHandler
        : public IInputControlHandler
    {
    public:
        virtual std::pair<int ,bool> onGetCheckState() const = 0;
        virtual void onCurrentIndexChanged(int) = 0;
        virtual void onCheckStatusChanged(int, bool) = 0;
    };

    class GNUF_BASE_EXPORT CheckGroupControlAdpatation
        : public InputControlAdaptation
    {
    protected:
        CheckGroupControlAdpatation();
        virtual ~CheckGroupControlAdpatation();

        //
        // Inherits from InputControlAdaptation...
        virtual void onVisibilityChanged(bool) override {}
        virtual void onSelectionChanged(bool) override {}

    public:
        virtual void onCurrentIndexChanged(int) {};
        virtual void onCheckStatusChanged(int, bool) {}
    };

    enum class ECheckGroupStyle : std::uint8_t
    {
        eCheckGroup,
        eRadioGroup,
        eButtonList
    };
    enum class ECheckGroupDirection : std::uint8_t
    {
        eVerticalDirection,
        eHorizenDirection
    };

    class GNUF_BASE_EXPORT CheckGroupControl
        : public InputControl
    {
        CANNOT_COPY_OR_ASSIGN(CheckGroupControl)
    public:
        static const EItemType Type;
        CheckGroupControl(ICheckGroupControlHandler *, ECheckGroupStyle, gcmp::OwnerPtr< Info > &, std::vector<gcmp::OwnerPtr<Info>>&,
           const std::vector<bool>& ,ECheckGroupDirection dir = ECheckGroupDirection::eVerticalDirection);
        virtual ~CheckGroupControl();

        inline ECheckGroupStyle style() const { return m_style; }
        inline ECheckGroupDirection direction() const { return m_dir; }
        inline const Info * info() const { return m_info.get(); }

        void GetList(std::vector<const Info*>& rawList) const;
        const std::vector<bool>& GetCheckStatus() const { return m_checkStatus; }

        void setCurrentIndex(int, const CheckGroupControlAdpatation * trigger = nullptr);
        void setCheckStatus(int, bool, const CheckGroupControlAdpatation* trigger = nullptr);
    private:
        const ECheckGroupStyle m_style;
        const ECheckGroupDirection m_dir;
        gcmp::OwnerPtr< Info > m_info;
        std::vector< gcmp::OwnerPtr< Info > > m_list;
        std::vector<bool> m_checkStatus;
    };

}
